package com.noble.library.host;

import com.noble.library.log.PSP;
import com.noble.library.utils.FileUtil;

/**
 * 地址配置
 */
public class Hosts {

    // --------------------逻辑服务器地址 start-----------------------
    public static String NO_HOST = "no_host";

    public static final String SERVER_TYPE_KEY = "SERVER_TYPE_KEY";//正式服测试服切换存储key
    // 0-正式服，1-测试服，对应以上几个host-array的position
    public static int SERVER_TYPE = PSP.getInstance().getInt(SERVER_TYPE_KEY, 0);

    // TCP长连接
    public static final String[] TCP_HOST = {"test.api.yanyuan01.cn", "test.api.yanyuan01.cn"};
    public static final String[] TCP_PORT = {"8823", "8823"};
    public static String FATE_IT_TCP = TCP_HOST[SERVER_TYPE];                    //socket地址
    public static int FATE_IT_TCP_PORT = Integer.valueOf(TCP_PORT[SERVER_TYPE]);//socket端口

    // 消息地址
    public static final String[] MSG_HOST = {"http://test.api.yanyuan01.cn:8822/", "http://test.api.yanyuan01.cn:8822/"};
    public static String FATE_IT_MSG = MSG_HOST[SERVER_TYPE];           //消息地址

    // Http Go地址
    public static final String[] GO_HOST = {"http://test.api.yanyuan01.cn:8080/", "http://test.api.yanyuan01.cn:8080/"};
    public static String FATE_IT_GO = GO_HOST[SERVER_TYPE];           //go地址

    // OSS文件存储地址
    public static final String[] OSS_HOST = {"http://test.api.yanyuan01.cn:8080/", "http://test.api.yanyuan01.cn:8080/"};
    public static String FATE_IT_OSS = OSS_HOST[SERVER_TYPE];          //文件地址

    // ============= 旧版 后续删除 =====================
    public static final String[] PHP_HOST = {"http://api2.app.yuanfenba.net/", "http://test.api2.app.yuanfenba.net/"};
    public static final String[] CONFIG_HOST = {"http://config.go.yuanfenba.net/", "http://configure.13.xiaoyouapp.cn/"};
    public static final String[] UPLOAD_HOST = {"http://upload.img.yuanfenba.net/", "http://test.upload.img.yuanfenba.net/"};
    public static final String[] PAY_HOST = {"http://p.app.yuanfenba.net/", "http://test.p.app.yuanfenba.net/"};
    private static final String[] CUP_HOST = {"http://pay.app.mumu123.cn/"};
    public static String FATE_IT_HTTP = PHP_HOST[SERVER_TYPE];        //php地址
    public static String FATE_CONFIG = CONFIG_HOST[SERVER_TYPE];      //在线配置host地址
    public static String FATE_IT_HTTP_PIC = UPLOAD_HOST[SERVER_TYPE]; //图片地址
    public static String FATE_IT_PROTOCOL = PAY_HOST[SERVER_TYPE];    //支付地址
    public static final String FATE_IT_CUP_HTTP = CUP_HOST[0];        //银联地址
    public static final String[] DOMAINNAME_BACKUP_TEST = new String[]{"http://domain.13.xiaoyouapp.cn/", "http://domain.13.xiaoyouapp.cn/", "http://domain.13.xiaoyouapp.cn/", "http://domain.13.xiaoyouapp.cn/"};//灾备域名
    public static final String[] DOMAINNAME_BACKUP_ONLINE = new String[]{"http://zhaoaiba.cn/", "http://zheiyuan.com/", "http://kouyin8.com/", "http://123.57.47.76/"};//批量查询有用域名，这个功能只能在线测试，不管测试包还是线上包，都用的这个地址
    public static final String[][] DOMAINNAME_BACKUP = {DOMAINNAME_BACKUP_ONLINE, DOMAINNAME_BACKUP_TEST};
    public static final String[] DOMAINTEST_ONLINE_ARR = DOMAINNAME_BACKUP[SERVER_TYPE];

    public static String HOST_URL = FATE_IT_HTTP;                     //默认host地址
    // -------------------逻辑服务器地址 end------------------------

    // ---------------------H5路径 start--------------------
//    public static String WEB_APP_ROOT = "http://page.xiaoyaoai.cn/app-b/";
    public static String WEB_APP_ROOT = "file:///android_asset/yfb/";

    public static String H5_RANKING = WEB_APP_ROOT + "pages/windRanking/windRanking.html";  // 排行榜
    public static String H5_ACTION = WEB_APP_ROOT + "pages/setting/activity.html";          // 活动相关
    public static String H5_PREPAID = WEB_APP_ROOT + "pages/vipAndKey/vipAndKey.html";      // VIP和购买钥匙页面
    public static String H5_PREPAID_Y = WEB_APP_ROOT + "pages/prepaid/prepaid.html";        // VIP和购买Y币页面
    public static String H5_GIFT = WEB_APP_ROOT + "pages/myGift/myGift.html";               // 我的礼物
    public static String H5_BILL = WEB_APP_ROOT + "pages/setting/tollCollection.html";      // 话费领取
    public static String H5_ROTARY = WEB_APP_ROOT + "pages/turntable/turntable.html";       // 大转盘设置
    public static String H5_EARN_RED_BAG = WEB_APP_ROOT + "pages/earnRedBag/earn-red-bag.html";    //我要赚红包

    public static String H5_EARN_MONEY = WEB_APP_ROOT + "pages/earnMoney/earnMoney.html";            //我要赚钱
    public static String H5_VIDEO_INVITE = WEB_APP_ROOT + "pages/activeVideoInvite/videoInvite.html";//主动视频邀请
    public static String H5_ASK_FOR_GIFT = WEB_APP_ROOT + "pages/askForGift/askForGift.html";        //索要礼物
    public static String H5_INCOME_DETAIL = WEB_APP_ROOT + "pages/incomeDetail/income-detail.html";  //收入明细
    public static String H5_MASS_VOICE = WEB_APP_ROOT + "pages/message/massVoice.html";              //群发语音
    public static String H5_MY_LEVEL = WEB_APP_ROOT + "pages/myLevel/myLevel.html";                  //我的等级

    public static String H5_APP_ABOUT = WEB_APP_ROOT + "pages/copyright/about.html";                  //关于页面
    public static String H5_APP_ANCHOR_MGR = WEB_APP_ROOT + "pages/copyright/AnchorManagement.html";  //主播管理规范
    public static String H5_APP_PLATFORN_MGR = WEB_APP_ROOT + "pages/copyright/platformSpecific.html";//平台规范
    public static String H5_APP_PRIVACY_POLICY = WEB_APP_ROOT + "pages/copyright/privacyPolicy.html"; // 隐私政策
    public static String H5_APP_REGISTER_AGREE = WEB_APP_ROOT + "pages/copyright/registerAgree.html"; // 用户注册协议
    public static String H5_APP_TIPS = WEB_APP_ROOT + "pages/copyright/tips.html";                    // 交友注意事项

    /**
     * 文件下载完成之后同步本地地址
     */
    public static void initWebAppUrl() {
//        String LOCAL_WEB_APP_ROOT = "file://" +
//                PSP.getInstance().getString(WebAppDownloader.KEY_WEB_APP_ROOT, WEB_APP_ROOT) + "/";
//
//        H5_RANKING = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/windRanking/windRanking.html");  // 排行榜
//        H5_ACTION = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/setting/activity.html");          // 活动相关
//        H5_PREPAID = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/vipAndKey/vipAndKey.html");      // VIP和购买钥匙页面
//        H5_PREPAID_Y = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/prepaid/prepaid.html");        // VIP和购买Y币页面
//        H5_GIFT = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/myGift/myGift.html");               // 我的礼物
//        H5_BILL = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/setting/tollCollection.html");      // 话费领取
//        H5_ROTARY = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/turntable/turntable.html");       // 大转盘设置
//        H5_EARN_RED_BAG = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/earnRedBag/earn-red-bag.html");    //我要赚红包
//
//        H5_EARN_MONEY = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/earnMoney/earnMoney.html");            //我要赚钱
//        H5_VIDEO_INVITE = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/activeVideoInvite/videoInvite.html");//主动视频邀请
//        H5_ASK_FOR_GIFT = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/askForGift/askForGift.html");        //索要礼物
//        H5_INCOME_DETAIL = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/incomeDetail/income-detail.html");  //收入明细
//        H5_MASS_VOICE = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/message/massVoice.html");              //群发语音
//        H5_MY_LEVEL = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/myLevel/myLevel.html");                  //我的等级
//
//        H5_APP_ABOUT = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/copyright/about.html");                  //关于页面
//        H5_APP_ANCHOR_MGR = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/copyright/AnchorManagement.html");  //主播管理规范
//        H5_APP_PLATFORN_MGR = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/copyright/platformSpecific.html");//平台规范
//        H5_APP_PRIVACY_POLICY = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/copyright/privacyPolicy.html"); // 隐私政策
//        H5_APP_REGISTER_AGREE = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/copyright/registerAgree.html"); // 用户注册协议
//        H5_APP_TIPS = getHtmlPath(LOCAL_WEB_APP_ROOT, "pages/copyright/tips.html");                    // 交友注意事项
    }
    // ---------------------H5路径 finish--------------------

    // -----------------------备份地址 start---------------------------

    /**
     * 获取本地路径纠错之后的最终路径
     *
     * @param localRoot 本地的h5文件存放根路径
     * @param path      h5文件的加载路径
     * @return 本地路径纠错之后的最终路径
     */
    private static String getHtmlPath(String localRoot, String path) {
        if (localRoot == null || path == null) return "";

        String localPath = localRoot + path;
        return FileUtil.isExist(localPath.replace("file://", "")) ? localPath : (WEB_APP_ROOT + path);
    }

    // 广场本地备份地址
    public static final String LOCAL_SQUARE_URL = "http://page.xiaoyaoai.cn/app/pages/square/square.html";
    // -----------------------备份地址 end---------------------------
}
